package org.come.baitan;


import com.google.gson.reflect.TypeToken;
import org.come.action.FromServerAction;
import org.come.until.GsonUtil;

import java.awt.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 式
 * @version 1.0
 * @project test1
 * @description 摆摊信息
 * @date 2024/2/3 11:04:22
 */
public class BaiTanMessageControl implements FromServerAction {
@Override
public void controlMessFromServer(String p0, String p1) {
	Type listType = new TypeToken<List<Record>>() {}.getType();
	List<Record> receivedRecordList = GsonUtil.getGsonUtil().getgson().fromJson(p0, listType);
	List<Record>shougou=new ArrayList<>();
	List<Record>chusou=new ArrayList<>();
	for (Record record:receivedRecordList){
		if (record.getRecordType()==100){
			shougou.add(record);
		}else if (record.getRecordType()==101){
			chusou.add(record);
		}
	}
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().goumaijilujpanel.setRecords(shougou);
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().shougoujilujpanel.setRecords(chusou);
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().goumaijilujpanel.setPreferredSize(new Dimension(20, shougou.size()*35));
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().shougoujilujpanel.setPreferredSize(new Dimension(20, chusou.size()*35));
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().goumaijilujpanel.revalidate();
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().goumaijilujpanel.repaint();;
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().shougoujilujpanel.revalidate();
	BaiTanJframe.getBaiTanJframe().getBaiTanJpanel().shougoujilujpanel.repaint();;
	
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().goumaijilujpanel.setRecords(shougou);
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().shougoujilujpanel.setRecords(chusou);
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().goumaijilujpanel.setPreferredSize(new Dimension(20, shougou.size()*35));
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().shougoujilujpanel.setPreferredSize(new Dimension(20, chusou.size()*35));
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().goumaijilujpanel.revalidate();
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().goumaijilujpanel.repaint();;
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().shougoujilujpanel.revalidate();
	GouMaizhuFrame.getGouMaizhuFrame().getGouMaiJpanel().shougoujilujpanel.repaint();;
}
}
